package com.uraurora.crescent.function.functools.memoizer;

import com.google.common.cache.Cache;
import com.uraurora.crescent.function.Func9;
import com.uraurora.crescent.tuple.ITuple;
import com.uraurora.crescent.tuple.Tuple;

import java.util.concurrent.Future;

public class MemoizerFunc9<T1, T2, T3, T4, T5, T6, T7, T8, T9, RT>
        extends AbstractMemoizer<RT>
        implements Func9<T1, T2, T3, T4, T5, T6, T7, T8, T9, RT> {

    private final Func9<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9, ? extends RT> computable;

    public MemoizerFunc9(Func9<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9, ? extends RT> computable,
                         Cache<ITuple, Future<RT>> cache) {
        super(cache);
        this.computable = computable;
    }

    public MemoizerFunc9(Func9<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9, ? extends RT> computable){
        super();
        this.computable = computable;
    }

    @Override
    public RT on(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) {
        return compute(Tuple.of(t1, t2, t3, t4, t5, t6, t7, t8, t9),
                ()->computable.on(t1, t2, t3, t4, t5, t6, t7, t8, t9));
    }
}